package com.ljt.system.controller;


import cn.hutool.core.lang.tree.Tree;
import com.ljt.response.Result;
import com.ljt.system.entity.Menu;
import com.ljt.system.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author ljt
 * @since 2021-06-28
 */
@RestController
@RequestMapping("/system/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @ApiOperation(value = "菜单信息",notes = "查询所有菜单信息")
    @GetMapping("queryAllMenu")
    public Result queryAllMenu(){
        List<Menu> menuList=menuService.list();
        return Result.ok().data("menuList",menuList);
    }

    @ApiOperation(value = "菜单信息",notes="删除菜单信息")
    @GetMapping("deleteMenuById")
    public Result deleteMenuById(int id){
        boolean i=menuService.removeById(id);
        if(i){
            return Result.ok();
        }else{
            return Result.error();
        }
    }

    @ApiOperation(value="菜单信息",notes="修改菜单信息")
    @GetMapping("updateMenuById")
    public Result updateMenuById(@RequestBody Menu menu) {
        boolean i=menuService.updateById(menu);
        if(i){
            return Result.ok();
        }else{
            return Result.error();
        }
    }

    @ApiOperation(value="菜单信息",notes="添加新菜单")
    @GetMapping("insertMenu")
    public Result insertMenu(@RequestBody Menu menu){
        boolean i=menuService.save(menu);
        if(i){
            return Result.ok();
        }else{
            return Result.error();
        }
    }
}

